<template>
    <div>
        <el-card style="text-align: left" v-for="spec in form.skuSpecs">
            <div slot="header">
                <span>{{spec.k}}</span>
            </div>
            <!--如果options长度为0，就显示出按钮和标签-->
            <div v-if="spec.options.length === 0">
                <el-button @click="addTag(spec)">添加</el-button>
                <div style="margin-top:10px">
                    <el-tag
                            :key="tag"
                            v-for="tag in spec.selected"
                            closable
                            :disable-transitions="false"
                            @close="deleteTag(spec.selected,tag)">
                        {{tag}}
                    </el-tag>
                </div>
            </div>
            <!--如果options长度大于0，就显示复选框-->
            <el-checkbox v-else v-for="op in spec.options" :label="op" :key="op" :value="op"
                         v-model="spec.selected"></el-checkbox>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: "GoodsSku",
        props: {
            form: {
                type: Object
            }
        },
        methods: {
            addTag(spec) {
                this.$prompt("请输入数据")
                    .then(({value}) => {
                        spec.selected.push(value);
                    });
            },
            deleteTag(selected, tag) {
                selected.splice(selected.indexOf(tag), 1);
            }
        },
        mounted() {
            console.log("----------");
            console.log(this.form.skuSpecs);
        }
    }
</script>

<style scoped>

</style>